from fastapi import APIRouter, Depends

from app.core.responses import Response
from app.schemas.gift import Gift
from app.services.auth import get_current_user
from app.services.gift import GiftServices

router = APIRouter()


@router.get('/gift')
def index():
    data = GiftServices.index()
    return Response.success({'list': data})


@router.post('/gift')
def gift(form: Gift):
    if GiftServices.store(form):
        return Response.success('操作成功！')


@router.delete('/gift/{id}')
def gift(gift_id: int):
    if GiftServices.destroy(gift_id):
        return Response.success('操作成功！')


@router.post('/gift/{id}')
def gift(gift_id: int, form: Gift):
    if GiftServices.update(gift_id, form):
        return Response.success('操作成功！')


@router.get('/gift_record')
def gift(user:str= Depends(get_current_user)):
    if GiftServices.list_record(user):
        return Response.success('操作成功！')


@router.delete('/gift_record/{id}')
def gift(gift_id: int):
    if GiftServices.destroy_record(gift_id):
        return Response.success('操作成功！')
